package com.moyq5.mvc.maker.test.bean.entity;

import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.Table;

import org.hibernate.annotations.DynamicUpdate;

import com.moyq5.mvc.maker.test.bean.embed.ShopUserId;

/**
 * 门店消费者（积分账户）信息
 * @author Moyq5
 * @date 2018年4月13日
 */
@Entity
@Table(name = "uc_shop_user")
@DynamicUpdate
public class ShopUser implements java.io.Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2863764765430536496L;
	/**
	 * 门店管理员ID
	 */
	@EmbeddedId
	@AttributeOverrides({
			@AttributeOverride(name = "shopId", column = @Column(name = "shop_id", nullable = false, precision = 15, scale = 0)),
			@AttributeOverride(name = "userId", column = @Column(name = "user_id", nullable = false, precision = 15, scale = 0)) })
	private ShopUserId id;
	/**
	 * 消费者
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "user_id", insertable = false, updatable = false)
	private User user;
	/**
	 * 门店
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "shop_id", insertable = false, updatable = false)
	private Shop shop;
	/**
	 * 商家
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "merch_id")
	private Merch merch;
	/**
     * 剩余积分
     */
    @Column(name = "remain", nullable = false, precision = 10, scale = 0)
    private Integer remain;
    /**
     * （已）消费积分
     */
    @Column(name = "consume", nullable = false, precision = 10, scale = 0)
    private Integer consume;
    /**
	 * 添加（注册）时间
	 */
	@Column(name = "add_time", nullable = false, columnDefinition="datetime")
	private Date addTime;
	
	@PrePersist
	public void prePersist() {
		if (null == addTime) {
			addTime = new Date();
		}
	}
	
	public ShopUserId getId() {
		return id;
	}
	public void setId(ShopUserId id) {
		this.id = id;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public Shop getShop() {
		return shop;
	}
	public void setShop(Shop shop) {
		this.shop = shop;
	}
	public Merch getMerch() {
		return merch;
	}
	public void setMerch(Merch merch) {
		this.merch = merch;
	}
	public Integer getRemain() {
		return remain;
	}
	public void setRemain(Integer remain) {
		this.remain = remain;
	}
	public Integer getConsume() {
		return consume;
	}
	public void setConsume(Integer consume) {
		this.consume = consume;
	}
	public Date getAddTime() {
		return addTime;
	}
	public void setAddTime(Date addTime) {
		this.addTime = addTime;
	}
	
}
